package com.yhk.usercenter.exception;

import com.yhk.usercenter.common.BaseResponse;
import com.yhk.usercenter.common.ErrorCode;
import com.yhk.usercenter.common.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @version 1.0
 * @Author moresuo
 * @Date 2023/12/11 23:33
 * @注释 全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public BaseResponse businessExceptionHandler(BusinessException e){
        log.error("business:"+e.getMessage(),e);
        return ResultUtil.error(e.getCode(), e.getMessage(), e.getDescription());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse businessExceptionHandler(RuntimeException e){
        log.error("runtime:",e);
        return ResultUtil.error(ErrorCode.SYSTEM_ERROE);
    }
}
